package com.sepro.action.admin;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.xwork.StringUtils;
import org.dom4j.DocumentException;
import javax.annotation.Resource;
import com.sepro.action.BaseAction;
import com.sepro.bean.PaymentProduct;
import com.sepro.service.PaymentConfigService;
import com.sepro.util.PaymentProductUtil;

public class PaymentTypeAction extends BaseAction {

	/**
	 * paymentAction serial version id
	 */
	private static final long serialVersionUID = -2890255925198178558L;

	private List<PaymentProduct> paymentProductList;
	private String name;
	private String logoPath;
	private String desp;
	private String bargainorIdName;
	private String bargainorKeyName;
	
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}


	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}


	/**
	 * @return the logoPath
	 */
	public String getLogoPath() {
		return logoPath;
	}


	/**
	 * @param logoPath the logoPath to set
	 */
	public void setLogoPath(String logoPath) {
		this.logoPath = logoPath;
	}


	/**
	 * @return the desp
	 */
	public String getDesp() {
		return desp;
	}


	/**
	 * @param desp the desp to set
	 */
	public void setDesp(String desp) {
		this.desp = desp;
	}


	/**
	 * @return the bargainorIdName
	 */
	public String getBargainorIdName() {
		return bargainorIdName;
	}


	/**
	 * @param bargainorIdName the bargainorIdName to set
	 */
	public void setBargainorIdName(String bargainorIdName) {
		this.bargainorIdName = bargainorIdName;
	}


	/**
	 * @return the bargainorKeyName
	 */
	public String getBargainorKeyName() {
		return bargainorKeyName;
	}


	/**
	 * @param bargainorKeyName the bargainorKeyName to set
	 */
	public void setBargainorKeyName(String bargainorKeyName) {
		this.bargainorKeyName = bargainorKeyName;
	}

	@Resource(name = "paymentConfigServiceImpl")
	private PaymentConfigService paymentConfigService;
	/**
	 * @return the paymentProductList
	 */
	public List<PaymentProduct> getPaymentProductList() {
		return paymentProductList;
	}


	/**
	 * @param paymentProductList the paymentProductList to set
	 */
	public void setPaymentProductList(List<PaymentProduct> paymentProductList) {
		this.paymentProductList = paymentProductList;
	}


	public String info(){
		
		//get payment product list
		paymentProductList = PaymentProductUtil.getPaymentProductList(paymentProductList);
		return "info";
	}
	
	public String addPayment(){
		
		if(StringUtils.isEmpty(name)){
			return ajax(Status.error, "支付产品名称不能为空!");
		}
		if(StringUtils.isEmpty(logoPath)){
			return ajax(Status.error, "支付产品图标不能为空!");
		}
		if(StringUtils.isEmpty(desp)){
			return ajax(Status.error, "支付产品说明不能为空!");
		}
		if(StringUtils.isEmpty(bargainorIdName)){
			return ajax(Status.error, "支付产品用户号不能为空!");
		}
		if(StringUtils.isEmpty(bargainorKeyName)){
			return ajax(Status.error, "支付产品用户密钥不能为空!");
		}
		
		String newId = paymentConfigService.addPaymentConfig(name, logoPath, desp, bargainorIdName, bargainorKeyName);
		
		return ajax(Status.success, newId);
	}
	
	
}
